{% extends 'admin/base.html' %}
{% import "admin/_macros.html" as macros %}

{% block title %}
    评论列表
{% endblock %}

{% block admin_content %}
    <div class="row">
        <div class="col-md-1"></div>
        <div class="col-md-10">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">文章评论</h3>
                </div>
                <div class="panel-body">
                    <div class="entry-box manage-comments">
                        <p><span class="glyphicon glyphicon-comment"></span>评论总数：<span
                                class="badge">{{ Comment.query.count() }}</span></p>
                        <div class="handle-box-admin">
                            <form id="delCommentsForm" method="post"
                                  action="{{ url_for('comment.delete_comments', page=page) }}">
                                {{ form2.csrf_token }}
                                {{ form2.commentIds(type='hidden') }}
                            </form>
                            <input type="checkbox" id="select-all" name="select-all" class="select-comments-admin">
                            <label for="select-all">全选</label>
                            <a class="btn btn-sm btn-danger delComments" id="delComments">
                                <span class="glyphicon glyphicon-trash"></span>批量删除
                            </a>
                        </div>
                        <ul class="comments">
                            {% for comment in comments %}
                                <li class="comment" style="display: flex;align-items: flex-start;justify-content: space-between;margin-top: 15px;">
                                    <div class="comment-thumbnail" style="display: inline-block;">
                                        <input type="checkbox" class="op_check op_check_com" value="{{ comment.id }}">&nbsp;
{#                                        <img class="img-rounded profile-thumbnail"#}
{#                                             src="{{ url_for('avatar',text = comment.author_name,width=35)}}">#}
                                    </div>
                                    <div class="comment-info-admin" style="display: inline-block;width: 410px;text-align: left;">
                                        <span style="font-size: 1.4rem;font-weight: bold;">
                                            在《<a href="{{ url_for('main.article_details', id=comment.article.id) }}"
                                                 target="_blank" >
                                            {{ comment.article.title }}
                                               </a>》
                                            发表评论：
                                        </span>
                                        <div class="comment-date">
                                            <span>
                                                <small>{{ moment(comment.timestamp.replace(microsecond=0)).format('LLL') }}</small>
                                            </span>
                                        </div>
                                        <div class="comment-content">
                                            {% if comment.comment_type == 'reply' %}
                                                <p class="comment-reply-info">
                                                    <span class="glyphicon glyphicon-envelope"></span>
                                                    回复给<strong><i>
                                                    {% if comment.followed_name() %}
                                                        {{ comment.followed_name() }}
                                                    {% else %}
                                                        {{ comment.reply_to }}
                                                        ({{ comment.reply_to }}的该条评论已经被删除！)
                                                    {% endif %}
                                                    ：</i></strong>
                                                </p>
                                            {% endif %}
                                            <p>{{ comment.content | safe }}</p>
                                            {% if comment.disabled == True %}
                                                <p class="disabled-comment-admin-info">
                                                    <span class="glyphicon glyphicon-remove-sign"></span>
                                                    <i>该评论已在文章页面中屏蔽！</i>
                                                </p>
                                            {% endif %}
                                        </div>
                                    </div>
                                    <div class="comment-info-admin" style="display: inline-block;">
{#                                        <span class="comment-author">#}
{#                                            {{ comment.author_name }}#}
{#                                            {{ comment.author_email }}#}
{#                                            {% if User.query.filter_by(email=comment.author_email).count() %}#}
{#                                                <span class="glyphicon glyphicon-user">管理员</span>#}
{#                                            {% endif %}#}
{#                                        </span>#}
                                        <a class="btn btn-sm btn-info comment-handle-admin" title="回复评论"
                                           onclick="pop_commentForm('{{ comment.id }}', '{{ comment.article.id }}')">
                                            <span class="glyphicon glyphicon-comment"></span>
                                        </a>
                                        <a class="btn btn-sm btn-danger comment-handle-admin delete-comment-admin-btn"
                                           title="删除评论"
                                           onclick="delCommentCfm('{{ url_for('comment.delete_comment', id=comment.id, page=page, delete_type='admin') }}')">
                                            <span class="glyphicon glyphicon-trash"></span>
                                        </a>
                                        {% if comment.disabled == True %}
                                            <a class="btn btn-sm btn-success comment-handle-admin enabled-comment-admin-btn"
                                               title="恢复评论"
                                               href="{{ url_for('comment.enable_comment', id=comment.id, page=page, enable_type='admin') }}">
                                                <span class="glyphicon glyphicon-ok-sign"></span>
                                            </a>
                                        {% else %}
                                            <a class="btn btn-sm btn-warning comment-handle-admin disabled-comment-admin-btn"
                                               title="屏蔽评论"
                                               href="{{ url_for('comment.disable_comment', id=comment.id, page=page, disable_type='admin') }}">
                                                <span class="glyphicon glyphicon-remove-sign"></span>
                                            </a>
                                        {% endif %}
                                    </div>
                                </li>
                            {% endfor %}
                        </ul>
                        <div class="pagination">
                            {{ macros.pagination_widget(pagination, endpoint) }}
                        </div>
                    </div>

                    <!-- 信息删除确认: For delete a comment confirm -->
                    <div class="modal fade" id="delCommentCfmModel">
                        <div class="modal-dialog">
                            <div class="modal-content message_align">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                            aria-hidden="true">×</span></button>
                                    <h4 class="modal-title">确认删除评论？</h4>
                                </div>
                                <div class="modal-body">
                                    <p>
                                        将该评论删除后不可恢复，您确认要删除吗？
                                    </p>
                                    <p>
                                        （提示：如果您只是不想显示该评论内容，可以选择将其屏蔽，而不必删除。）
                                    </p>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <a onclick="" id="delCommentCfmClick" class="btn btn-success" data-dismiss="modal">确定</a>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->

                    <!-- 信息删除确认: For select comments confirm -->
                    <div class="modal fade" id="selComsCfmModal">
                        <div class="modal-dialog">
                            <div class="modal-content message_align">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                            aria-hidden="true">×</span></button>
                                    <h4 class="modal-title">未选择评论</h4>
                                </div>
                                <div class="modal-body">
                                    <p>请选择您要删除的评论！</p>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <a class="btn btn-success" data-dismiss="modal">确定</a>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->

                    <!-- 信息删除确认: For delete comments confirm -->
                    <div class="modal fade" id="delComsCfmModel">
                        <div class="modal-dialog">
                            <div class="modal-content message_align">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                            aria-hidden="true">×</span></button>
                                    <h4 class="modal-title">确认删除所选评论？</h4>
                                </div>
                                <div class="modal-body">
                                    <p>将评论删除后不可恢复，您确认要删除所选评论吗？</p>
                                    <p>
                                        （提示：如果您只是不想显示该评论内容，可以选择将其屏蔽，而不必删除。）
                                    </p>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <a id="delComsCfm" class="btn btn-success" data-dismiss="modal">确定</a>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->

                    <!-- 信息删除确认: For comment form-->
                    <div class="modal fade" id="commentFormModel">
                        <div class="modal-dialog">
                            <div class="modal-content message_align">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                            aria-hidden="true">×</span></button>
                                    <h4 class="modal-title">提交评论（管理员）</h4>
                                </div>
                                <form id="commentForm" method="post" action="">
                                    <div class="modal-body">

                                        <div class="form-group">
                                            {{ form.csrf_token }}
{#                                            {{ form.follow(type='hidden') }}#}
                                            {{ form.article(type='hidden') }}
{#                                            {{ form.name.label }}#}
{#                                            {{ form.name(class='form-control', required='', readonly='true', value=current_user.username) }}#}
                                            {{ form.email.label }}
                                            {{ form.email(class='form-control', required='', readonly='true', value=current_user.email) }}
                                            {{ form.content.label }}{{ form.content(class='form-control', required='') }}
                                        </div>

                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                        <button type="submit" id="subCommentCfmClick" class="btn btn-success">确定
                                        </button>
                                    </div>
                                </form>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->
                </div>
            </div>
        </div>
    </div>

{% endblock %}
